<template>
  <div>
    <Row :space="10">
      <Cell width="12"
        ><Form
          labelPosition="left"
          :label-width="110"
          :model="form"
          :rules="validationRules"
          ref="form"
          :top="0.2"
          showErrorTip
        >
          <FormItem label="域名" single prop="domain" v-width="500">
            <div class="h-input-group">
              <div class="h-input-addon">
                <Select
                  :deletable="false"
                  :no-border="true"
                  v-model="select"
                  :datas="param"
                ></Select>
              </div>
              <input
                type="text"
                v-model="form.domain"
                placeholder="输入域名：选择HTTP或者HTTPS并录入域名"
              />
            </div>
          </FormItem>
          <FormItem label="前台网站根目录" single prop="path" v-width="500">
            <input
              type="text"
              v-model="form.path"
              placeholder="输入网站部署目录"
            />
          </FormItem>
          <FormItem label="百度token" single prop="baidu_token" v-width="500">
            <input
              type="text"
              v-model="form.baidu_token"
              placeholder="输入token：16个英文数字组合的字符串"
            />
          </FormItem>
          <FormItem>
            <Button color="primary" @click="pusher">主动推送链接</Button>
            <Button color="primary" @click="writeSiteMap">生成站点地图</Button>
          </FormItem>
        </Form>
      </Cell>
      <Cell width="8">
        <div class="contact">
          <div class="h-tag">
            <a
              target="_blank"
              href="http://wpa.qq.com/msgrd?v=3&uin=525847633&site=qq&menu=yes"
              >此项有问题请点击联系我</a
            >
          </div>
          <div class="h-tag" v-font="15" v-color:red>
            主动推送链接方式请自行获取对应token，主动推送一天一次即可
          </div>
          <div class="h-tag" v-font="15" v-color:red>
            配置了前台网站目录，站点地图为：
            <br />
            你的域名/sitemap.xml
            <br />
            未配置站点地图目录。站点地图为:
            https://admin.wineforyou.cn/sitemap.xml
          </div>
        </div>
      </Cell>
    </Row>
  </div>
</template>
<script>
export default {
  name: "setSitemap",
  data() {
    return {
      select: "https://",
      param: [
        { title: "http://", key: "http://" },
        { title: "https://", key: "https://" },
      ],
      form: {
        domain: "www.wineforyou.cn",
        path: "",
        baidu_token: process.env.VUE_APP_baidu_token,
      },
      validationRules: {
        required: ["domain"],
      },
    };
  },
  methods: {
    async pusher() {
      let validResult = this.$refs.form.valid();
      if (validResult.result) {
        if (validResult.result) {
          let res = await this.$post("/api/site/baidupusher", {
            domain: this.select + this.form.domain,
            baidu_token: this.form.baidu_token,
          });
          if (res && res.code === 200) {
            this.$Message.success("推送成功");
          } else {
            this.$Message.error(res.message);
          }
        }
      }
    },
    async writeSiteMap() {
      let validResult = this.$refs.form.valid();
      if (validResult.result) {
        let res = await this.$post("/api/site/sitemap", {
          domain: this.select + this.form.domain,
          path: this.form.path,
        });
        if (res && res.code === 200) {
          this.$Message.success("创建站点地图成功");
        } else {
          this.$Message.error(res.message);
        }
      }
    },
  },
  mounted() {
    // console.info("站点地图默认会放到项目public目录");
  },
};
</script>
<style lang="less" scoped>
.contact {
  height: 40px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;

  .h-tag {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    line-height: 40px;
    margin: 5px;
  }
}
</style>